package com.FH.applyFrom.meeting_room;

import com.FH.applyForm.officeServies.meeting.MeetingPullDTO;
import com.FH.applyForm.officeServies.meeting.MeetingResource;
import com.FH.applyForm.officeServies.meeting.MeetingShowDTO;
import com.FH.applyForm.officeServies.meeting_Type.meetmanagerResource;
import com.FH.organization.Attachment.AttachmentResource;
import com.FH.organization.diarytask_manager.DiaryTaskPullDTO;
import com.FH.organization.diarytask_manager.DiaryTaskResource;
import com.FH.organization.operator_log.OperatorLogPullDTO;
import com.FH.organization.operator_log.OperatorLogResource;
import com.FH.organization.remind.RemindPullDTO;
import com.FH.organization.remind.RemindResource;
import com.FH.organization.suggestion.SuggestionResource;
import com.FH.organization.work_flow.WorkFlowPullDTO;
import com.FH.organization.work_flow.WorkFlowResource;
import com.FH.util.AccessDB;
import com.FH.util.FileProcess;
import com.FH.util.ResultDTO;
import com.FH.util.warnSrc;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

import javax.ejb.Stateless;
import javax.inject.Inject;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by acer on 2016/7/15.
 */
@Stateless
public class MeetingRoomDAOImpl extends AccessDB implements MeetingRoomDAO {

    /**
     * 获取会议室信息
     *
     * @param search
     * @param page
     * @param size
     * @return
     */

    @Inject
    OperatorLogResource operatorLogResource;

    @Inject
    WorkFlowResource workFlowResource;

    @Inject
    MeetingRoomResource meetingRoomResource;

    @Inject
    MeetingResource meetingResource;

    @Inject
    meetmanagerResource meetmanagerResource;
    @Inject
    AttachmentResource attachmentResource;
    @Inject
    DiaryTaskResource taskResource;
    @Inject
    RemindResource remindResource;
    @Inject
    SuggestionResource suggestionResource;


    public ResultDTO getMeetingRoomInfo(String search, String page, String size) {

        ResultDTO resultDTO = new ResultDTO();
        try {
            JSONObject json = new JSONObject(search);
            String existName = "0";

            String sqlexit = "select count(1) from meeting_room where 1=1 ";

            String sql_w = "";//查询条件sql组合

            String sql_page = "";//分页sql组合
            Integer page_ok = Integer.parseInt(page);
            Integer size_ok = Integer.parseInt(size);
            if (page.equals("1")) {
                sql_page = " limit 0," + size + "";
            } else {
                sql_page = " limit " + ((page_ok - 1) * size_ok) + "," + size + "";
            }

            if (json.has("isverify")) {
                sql_w += " AND isverify ='" + json.getString("isverify") + "'";
            }
//            else {
//                sql_w += " AND (isverify IS NULL OR isverify=0)";
//            }


            if (json.has("meeting_room_id")) {
                sql_w += " AND meeting_room_id = '" + json.getString("meeting_room_id") + "'";
            }
            if (json.has("member_id")) {
                sql_w += " AND member_id = '" + json.getString("member_id") + "'";
            }
            String sql_ok = sqlexit + sql_w;//组合好的sql语句
            existName = getReportingToOne(sql_ok);

            List<String[]> seresult = new ArrayList<String[]>();

            List<MeetingRoomShowDTO> result = new ArrayList<MeetingRoomShowDTO>();
            if (!existName.equals("0")) {
                String sql = "select isverify,meeting_room_id,meeting_room_name,meeting_room_desc, " +
                        "meeting_room_starttime,meeting_room_endtime,member_id,fail_resource ,meet_type_id,is_circle_time,circle_time_start,circle_time_end,circle_time_piker_start,circle_time_piker_end,pre_time_warn,issendemail,iswriteschedule,attachment_id,weeks from meeting_room where 1=1" + sql_w + " ORDER BY create_time DESC" + sql_page;
                seresult = this.getReportingTo(sql);

                //构建返回对象
                for (int i = 0; i < seresult.size(); i++) {

                    MeetingRoomShowDTO meetingroom = new MeetingRoomShowDTO();
                    meetingroom.setIsverify(seresult.get(i)[1]);
                    meetingroom.setMeeting_room_id(seresult.get(i)[2]);
                    meetingroom.setMeeting_room_name(seresult.get(i)[3]);
                    meetingroom.setMeeting_room_desc(seresult.get(i)[4]);
                    meetingroom.setMeeting_room_starttime(seresult.get(i)[5]);
                    meetingroom.setMeeting_room_endtime(seresult.get(i)[6]);
                    meetingroom.setMember_id(seresult.get(i)[7]);
                    meetingroom.setFail_resource(seresult.get(i)[8]);
                    meetingroom.setMeet_type_id(seresult.get(i)[9]);
                    meetingroom.setIs_circle_time(seresult.get(i)[10]);
                    meetingroom.setCircle_time_start(seresult.get(i)[11]);
                    meetingroom.setCircle_time_end(seresult.get(i)[12]);
                    meetingroom.setCircle_time_piker_start(seresult.get(i)[13]);
                    meetingroom.setCircle_time_piker_end(seresult.get(i)[14]);
                    meetingroom.setPre_time_warn(seresult.get(i)[15]);
                    meetingroom.setIssendemail(seresult.get(i)[16]);
                    meetingroom.setIswriteschedule(seresult.get(i)[17]);
                    meetingroom.setAttachment_id(seresult.get(i)[18]);
                    meetingroom.setWeeks(seresult.get(i)[19]);

                    ResultDTO worklist = null, jsonpeople = null, meetaddr = null, attach = null,suggestion=null;

                    if (json.has("isverify")) {
                        String state = json.getString("isverify");
                        worklist = workFlowResource.getWorkFlowInfo("{work_flow_formid:" + seresult.get(i)[2] + ",work_flow_state:" + state + "}", "1", "20");
                    } else {
                        worklist = workFlowResource.getWorkFlowInfo("{work_flow_formid:" + seresult.get(i)[2] + "}", "1", "20");
                    }

                    meetingroom.setWs(worklist.getValues());

                    jsonpeople = meetingResource.getMeetingInfo("{meeting_room_id:" + seresult.get(i)[2] + "}", "1", "1000");
                    meetingroom.setMs(jsonpeople.getValues());


                    meetaddr = meetmanagerResource.getmeetInfo("{meet_type_id:" + seresult.get(i)[9] + "}", "1", "1");
                    meetingroom.setMeetaddr(meetaddr.getValues());

                    if (!seresult.get(i)[18].equals("") && seresult.get(i)[18] != null) {
                        attach = attachmentResource.getAttachmentInfo("{attachment_id:" + seresult.get(i)[18] + "}", "1", "1");
                        meetingroom.setAttachmentShowDTOs(attach.getValues());
                    }
                    if(seresult.get(i)[2] != null && ! seresult.get(i)[2].equals("")){

                        suggestion=suggestionResource.getSuggestionInfo("{form_id:" + seresult.get(i)[2] + "}", "1", "100");
                        meetingroom.setSuggestionShowDTOs(suggestion.getValues());
                    }
                    result.add(meetingroom);
                }
            }


            if (seresult.size() != 0) {
                resultDTO.setStatus("90000");
                resultDTO.setDescritpion(warnSrc.get_success);
            } else {
                resultDTO.setStatus("90001");
                resultDTO.setDescritpion(warnSrc.get_fail);
            }
            resultDTO.setStr(result.size() + "");
            resultDTO.setValues(result);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return resultDTO;


    }

    /**
     * 增加会议室信息
     *
     * @param meetingRoomPullDTO
     * @return
     */
    public ResultDTO addMeetingRoomInfo(MeetingRoomPullDTO meetingRoomPullDTO) {

        String exit = "select count(1) from meeting_room where meeting_room_id='" + meetingRoomPullDTO.getMeeting_room_id() + "'";
        String existone = getReportingToOne(exit);

        if (!existone.equals("0")) {
            return updateMeetingRoomInfo(meetingRoomPullDTO);

        }


        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = df.format(new Date());

        //构建返回对象
        ResultDTO resultDTO = new ResultDTO();
        String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");

        int resultls = 0;

        /**
         * 将要申请的会议室  时间差的比较
         *
         */
        String meeting_room_starttime = meetingRoomPullDTO.getMeeting_room_starttime();//将要申请的会议室的开始时间
        String meet_type_id = meetingRoomPullDTO.getMeet_type_id();//所申请的会议室id

//        String sql = "select count(1) from meeting_room where meeting_room_endtime >= '" + meetingRoomPullDTO.getMeeting_room_starttime() + "' AND  meet_type_id =  '" + meetingRoomPullDTO.getMeet_type_id() + "' ";
//        String sql = "select count(1) from meeting_room where((meeting_room_endtime < '" + meetingRoomPullDTO.getMeeting_room_starttime() + "') and (meeting_room_starttime>'" + meetingRoomPullDTO.getMeeting_room_endtime() + "')) AND  meet_type_id =  '" + meetingRoomPullDTO.getMeet_type_id() + "' ";
        String sql = "select count(1) from meeting_room where((meeting_room_starttime>='" + meetingRoomPullDTO.getMeeting_room_starttime() + "') and (meeting_room_endtime<='"+meetingRoomPullDTO.getMeeting_room_endtime()+"')) AND  meet_type_id =  '" + meetingRoomPullDTO.getMeet_type_id() + "' ";
        String existName = getReportingToOne(sql);

        if (!existName.equals("0")) {

            resultDTO.setStatus("90001");
            resultDTO.setDescritpion("会议室已被占用");
            return resultDTO;
        }
        String uid = "";
        if (null != meetingRoomPullDTO.getFile_type() && !"".equals(meetingRoomPullDTO.getFile_type())) {
            uid = getImage(meetingRoomPullDTO);
        }

//        if(!meetingRoomPullDTO.getIs_circle_time().equals("0")){
//
//            /**
//             * 比较时间差
//             */
//            String exitName = "";
//            String sql1 = "select count(1) form meeting_room where is_circle_time ";
//
//
//        }
        String meetingRoom_insert = "";
        meetingRoom_insert += "insert into meeting_room (meeting_room_id,meeting_room_name,meeting_room_desc,meeting_room_starttime" +
                ",meeting_room_endtime,member_id,isverify,meet_type_id,is_circle_time,circle_time_start,circle_time_end,circle_time_piker_start,circle_time_piker_end,pre_time_warn,create_time,issendemail,iswriteschedule,attachment_id,weeks)" +
                "values ('" + uuid + "','" + meetingRoomPullDTO.getMeeting_room_name() + "','" + meetingRoomPullDTO.getMeeting_room_desc() + "','" + meetingRoomPullDTO.getMeeting_room_starttime() + "'" +
                ",'" + meetingRoomPullDTO.getMeeting_room_endtime() + "','" + meetingRoomPullDTO.getMember_id() + "','0','" + meetingRoomPullDTO.getMeet_type_id() + "','" + meetingRoomPullDTO.getIs_circle_time() + "'" +
                ",'" + meetingRoomPullDTO.getCircle_time_start() + "','" + meetingRoomPullDTO.getCircle_time_end() + "','" + meetingRoomPullDTO.getCircle_time_piker_start() + "','" + meetingRoomPullDTO.getCircle_time_piker_end() + "'" +
                ",'" + meetingRoomPullDTO.getPre_time_warn() + "','" + df.format(new Date()) + "','" + meetingRoomPullDTO.getIssendemail() + "','" + meetingRoomPullDTO.getIswriteschedule() + "','" + uid + "'" +
                ",'" + meetingRoomPullDTO.getWeeks() + "')";
        //插入业务表
        resultls = addReportingTo(meetingRoom_insert);


        if (resultls != 0) {
            resultDTO.setStr(uuid);
            resultDTO.setStatus("90000");
            resultDTO.setDescritpion(warnSrc.get_success);

            /**
             * JSON解析集合、参会人
             */
            if (null != meetingRoomPullDTO.getJoinmen() && !"".equals(meetingRoomPullDTO.getJoinmen())) {
                String json_joinmen = meetingRoomPullDTO.getJoinmen();
                try {
                    JSONArray array = new JSONArray(json_joinmen);
                    if (array != null && array.length() > 0) {
                        List<MeetingRoomPullDTO> result = new ArrayList<MeetingRoomPullDTO>();
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject jsonObject = array.getJSONObject(i);
                            String id = jsonObject.getString("id");
                            String name = jsonObject.getString("name");
                            MeetingPullDTO meetingPullDTO = new MeetingPullDTO();
                            meetingPullDTO.setMeeting_room_id(uuid);
                            meetingPullDTO.setMember_id(id);
                            meetingPullDTO.setMember_name(name);
                            meetingResource.addMeetingInfo(meetingPullDTO);
                        }
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }

            }

            if (meetingRoomPullDTO.getIswriteschedule().equals("1")) {
                if (!meetingRoomPullDTO.getIs_circle_time().equals("1")) {
                    //非周期性日程
                    DiaryTaskPullDTO diaryTaskPullDTO = new DiaryTaskPullDTO();
                    diaryTaskPullDTO.setSchedule_title(meetingRoomPullDTO.getMeeting_room_name());
                    diaryTaskPullDTO.setSchedule_addr("");
                    diaryTaskPullDTO.setSchedule_desc("");
                    diaryTaskPullDTO.setSchedule_starttime(meetingRoomPullDTO.getMeeting_room_starttime());
                    diaryTaskPullDTO.setSchedule_endtime(meetingRoomPullDTO.getMeeting_room_endtime());
                    diaryTaskPullDTO.setSchedule_status("");
                    diaryTaskPullDTO.setMember_id(meetingRoomPullDTO.getMember_id());
                    diaryTaskPullDTO.setType("1");
                    diaryTaskPullDTO.setMeeting_room_id(uuid);
                    taskResource.addDiaryTaskInfo(diaryTaskPullDTO);
                } else {
                    //周期性日程
                    try {
                        String weeks[] = meetingRoomPullDTO.getWeeks().split(",");
                        //for (int i = 0; i < weeks.length; i++) {
                        SimpleDateFormat weekdf = new SimpleDateFormat("EEEE");
                        SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");
                        Date start = df2.parse(meetingRoomPullDTO.getCircle_time_start());
                        Date end = df2.parse(meetingRoomPullDTO.getCircle_time_end());

                        long l = end.getTime() - start.getTime();
                        long day = l / (24 * 60 * 60 * 1000);//时间差
                        //int daynumber = (int) (day / 7);

                        //判断第一个日期是不是当前的周期
                        Calendar firstday = Calendar.getInstance();
                        firstday.setTime(start);
                        int firstw = firstday.get(Calendar.DAY_OF_WEEK) - 1;//获取当前日期是星期几
                        if (firstw < 0)
                            firstw = 0;
                        for (int k = 0; k < weeks.length; k++) {
                            int week=Integer.parseInt(weeks[k]);//判断是否是周期内的时间
                            if(week==firstw){
                                String Circle_time_start = df2.format(firstday.getTime());
                                DiaryTaskPullDTO diaryTaskPullDTO = new DiaryTaskPullDTO();
                                diaryTaskPullDTO.setSchedule_title(meetingRoomPullDTO.getMeeting_room_name());
                                diaryTaskPullDTO.setSchedule_addr("");
                                diaryTaskPullDTO.setSchedule_desc("");
                                if (!meetingRoomPullDTO.getIs_circle_time().equals("1")) {
                                    diaryTaskPullDTO.setSchedule_starttime(meetingRoomPullDTO.getMeeting_room_starttime());
                                    diaryTaskPullDTO.setSchedule_endtime(meetingRoomPullDTO.getMeeting_room_endtime());
                                } else {
                                    diaryTaskPullDTO.setSchedule_starttime(Circle_time_start + " " + meetingRoomPullDTO.getCircle_time_piker_start());
                                    diaryTaskPullDTO.setSchedule_endtime(Circle_time_start + " " + meetingRoomPullDTO.getCircle_time_piker_end());
                                }
                                diaryTaskPullDTO.setSchedule_status("");
                                diaryTaskPullDTO.setMember_id(meetingRoomPullDTO.getMember_id());
                                diaryTaskPullDTO.setType("1");
                                diaryTaskPullDTO.setMeeting_room_id(uuid);
                                taskResource.addDiaryTaskInfo(diaryTaskPullDTO);
                            }


                        }

                        Calendar c = Calendar.getInstance();
                        c.setTime(start);
                        //判断后一个日期是不是当前的周期
                        for (int i = 0; i < (day); i++) {
                            c.set(Calendar.DATE, c.get(Calendar.DATE) + 1);//开始日期的后一天
                            int w = c.get(Calendar.DAY_OF_WEEK) - 1;//获取当前日期是星期几
                            if (w < 0)
                                w = 0;
                            for (int j = 0; j < weeks.length; j++) {
                                int week=Integer.parseInt(weeks[j]);//判断是否是周期内的时间
                                if(week==w){
                                    String Circle_time_start = df2.format(c.getTime());
                                    DiaryTaskPullDTO diaryTaskPullDTO = new DiaryTaskPullDTO();
                                    diaryTaskPullDTO.setSchedule_title(meetingRoomPullDTO.getMeeting_room_name());
                                    diaryTaskPullDTO.setSchedule_addr("");
                                    diaryTaskPullDTO.setSchedule_desc("");
                                    if (!meetingRoomPullDTO.getIs_circle_time().equals("1")) {
                                        diaryTaskPullDTO.setSchedule_starttime(meetingRoomPullDTO.getMeeting_room_starttime());
                                        diaryTaskPullDTO.setSchedule_endtime(meetingRoomPullDTO.getMeeting_room_endtime());
                                    } else {
                                        diaryTaskPullDTO.setSchedule_starttime(Circle_time_start + " " + meetingRoomPullDTO.getCircle_time_piker_start());
                                        diaryTaskPullDTO.setSchedule_endtime(Circle_time_start + " " + meetingRoomPullDTO.getCircle_time_piker_end());
                                    }
                                    diaryTaskPullDTO.setSchedule_status("");
                                    diaryTaskPullDTO.setMember_id(meetingRoomPullDTO.getMember_id());
                                    diaryTaskPullDTO.setType("1");
                                    diaryTaskPullDTO.setMeeting_room_id(uuid);
                                    taskResource.addDiaryTaskInfo(diaryTaskPullDTO);
                                }


                            }
                        }


                        //   }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }

            //日志操作
            OperatorLogPullDTO operatorlogPullDTO = new OperatorLogPullDTO();
            operatorlogPullDTO.setWork_form_id(uuid);
            operatorlogPullDTO.setOperator_log_type("会议室申请");
            operatorlogPullDTO.setOperator_log_title(meetingRoomPullDTO.getMeeting_room_name());
            operatorlogPullDTO.setOperator_log_content(meetingRoomPullDTO.getMeeting_room_desc());
            operatorlogPullDTO.setMember_id(meetingRoomPullDTO.getMember_id());
            operatorLogResource.addOperatorLogInfo(operatorlogPullDTO);

            //流程上报

            WorkFlowPullDTO workFlowPullDTO = new WorkFlowPullDTO();
            workFlowPullDTO.setWork_flow_formid(uuid);
            workFlowPullDTO.setWork_flow_type("meeting_room");
            workFlowPullDTO.setWork_flow_desc("会议室申请请求审批");
            workFlowPullDTO.setWork_flow_date(time);
            workFlowPullDTO.setWork_flow_order("0");
            workFlowPullDTO.setWork_flow_createid(meetingRoomPullDTO.getMember_id());
            workFlowPullDTO.setWork_flow_approval(meetingRoomPullDTO.getReport_people());
            workFlowPullDTO.setWork_flow_approval_organization_id(meetingRoomPullDTO.getWork_flow_approval_organization_id());
            workFlowPullDTO.setFlow_path_id(meetingRoomPullDTO.getFlow_path_id());
            workFlowPullDTO.setWork_flow_suggestion("");
            workFlowResource.addWorkFlowInfo(workFlowPullDTO);


            ResultDTO contractwarnperplelist = null;
            String meeting_room_id = meetingRoomPullDTO.getMeeting_room_id();
            contractwarnperplelist = meetingResource.getMeetingInfo("{meeting_room_id:"+uuid+"}","1","20");
            ArrayList<MeetingShowDTO> mens = (ArrayList<MeetingShowDTO>)contractwarnperplelist.getValues();
            for(int i = 0;i<mens.size();i++){
                MeetingShowDTO meetingShowDTO= mens.get(i);
                /**
                 * 事物提醒
                 */
                RemindPullDTO remindPullDTO = new RemindPullDTO();
                remindPullDTO.setRemind_content(meetingRoomPullDTO.getMeeting_room_desc());
                remindPullDTO.setRemind_time(meetingRoomPullDTO.getMeeting_room_starttime());
                remindPullDTO.setRemind_type("4");
                remindPullDTO.setRemind_form_id(uuid);
                remindPullDTO.setRemind_order("0");
                remindPullDTO.setCreate_time(time);
                remindPullDTO.setRemind_endtime(meetingRoomPullDTO.getMeeting_room_endtime());
                remindPullDTO.setRemind_member_id(meetingShowDTO.getMember_id());
                remindPullDTO.setRemind_starttime(meetingRoomPullDTO.getMeeting_room_starttime());
                remindPullDTO.setRemind_descritpion("您有一个会议即将开始，请注意查看！");
                remindResource.addRemindInfo(remindPullDTO);
            }



        } else {
            resultDTO.setStatus("90001");
            resultDTO.setDescritpion(warnSrc.get_fail);
        }

        return resultDTO;

    }

    /**
     * 更新会议室信息
     *
     * @param meetingRoomPullDTO
     * @return
     */
    public ResultDTO updateMeetingRoomInfo(MeetingRoomPullDTO meetingRoomPullDTO) {

        ResultDTO resultss = null;
        String meeting_room_id = meetingRoomPullDTO.getMeeting_room_id();
        MeetingPullDTO meetingPullDTOdelete = new MeetingPullDTO();
        meetingPullDTOdelete.setMeeting_room_id(meeting_room_id);
        meetingResource.deleteMeetingInfo(meetingPullDTOdelete);
        //  if(resultss!=null){
        if (null != meetingRoomPullDTO.getJoinmen() && !"".equals(meetingRoomPullDTO.getJoinmen())) {
            String json_joinmen = meetingRoomPullDTO.getJoinmen();
            try {
                JSONArray array = new JSONArray(json_joinmen);
                if (array != null && array.length() > 0) {
                    List<MeetingRoomPullDTO> result = new ArrayList<MeetingRoomPullDTO>();
                    for (int i = 0; i < array.length(); i++) {
                        JSONObject jsonObject = array.getJSONObject(i);
                        String id = jsonObject.getString("id");
                        String name = jsonObject.getString("name");
                        MeetingPullDTO meetingPullDTO = new MeetingPullDTO();
                        meetingPullDTO.setMeeting_room_id(meetingRoomPullDTO.getMeeting_room_id());
                        meetingPullDTO.setMember_id(id);
                        meetingPullDTO.setMember_name(name);
                        meetingResource.addMeetingInfo(meetingPullDTO);
                    }
                }

            } catch (Exception e) {
                e.printStackTrace();
            }

        }

        //  }


        String sql_isHas = "select count(1) from meeting_room WHERE meeting_room_id='" + meetingRoomPullDTO.getMeeting_room_id() + "'";

        String existMeetingRoom = getReportingToOne(sql_isHas);

        int resultls = 0;
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = df.format(new Date());

        //构建返回对象
        ResultDTO resultDTO = new ResultDTO();
        if (!existMeetingRoom.equals("0")) {
            String meetingRoom_update = "";
            meetingRoom_update += "update meeting_room set  update_time='" + time + "'";
            if (null != meetingRoomPullDTO.getMeeting_room_name() && !"".equals(meetingRoomPullDTO.getMeeting_room_name())) {
                meetingRoom_update += ",meeting_room_name='" + meetingRoomPullDTO.getMeeting_room_name() + "'";
            }

            if (null != meetingRoomPullDTO.getMeeting_room_desc() && !"".equals(meetingRoomPullDTO.getMeeting_room_desc())) {
                meetingRoom_update += ",meeting_room_desc='" + meetingRoomPullDTO.getMeeting_room_desc() + "'";
            }
            if (null != meetingRoomPullDTO.getMeeting_room_starttime() && !"".equals(meetingRoomPullDTO.getMeeting_room_starttime())) {
                meetingRoom_update += ",meeting_room_starttime='" + meetingRoomPullDTO.getMeeting_room_starttime() + "'";
            }
            if (null != meetingRoomPullDTO.getMeeting_room_endtime() && !"".equals(meetingRoomPullDTO.getMeeting_room_endtime())) {
                meetingRoom_update += ",meeting_room_endtime='" + meetingRoomPullDTO.getMeeting_room_endtime() + "'";
            }

            if (null != meetingRoomPullDTO.getMeet_type_id() && !"".equals(meetingRoomPullDTO.getMeet_type_id())) {
                meetingRoom_update += ",meet_type_id='" + meetingRoomPullDTO.getMeet_type_id() + "'";
            }
            if (null != meetingRoomPullDTO.getIsverify() && !"".equals(meetingRoomPullDTO.getIsverify())) {
                meetingRoom_update += ",isverify='" + meetingRoomPullDTO.getIsverify() + "'";
            }


            if (null != meetingRoomPullDTO.getIs_circle_time() && !"".equals(meetingRoomPullDTO.getIs_circle_time())) {
                meetingRoom_update += ",is_circle_time='" + meetingRoomPullDTO.getIs_circle_time() + "'";
            }

            if (null != meetingRoomPullDTO.getCircle_time_start() && !"".equals(meetingRoomPullDTO.getCircle_time_start())) {
                meetingRoom_update += ",circle_time_start='" + meetingRoomPullDTO.getCircle_time_start() + "'";
            }
            if (null != meetingRoomPullDTO.getCircle_time_end() && !"".equals(meetingRoomPullDTO.getCircle_time_end())) {
                meetingRoom_update += ",circle_time_end='" + meetingRoomPullDTO.getCircle_time_end() + "'";
            }
            if (null != meetingRoomPullDTO.getCircle_time_piker_start() && !"".equals(meetingRoomPullDTO.getCircle_time_piker_start())) {
                meetingRoom_update += ",circle_time_piker_start='" + meetingRoomPullDTO.getCircle_time_piker_start() + "'";
            }

            if (null != meetingRoomPullDTO.getCircle_time_piker_end() && !"".equals(meetingRoomPullDTO.getCircle_time_piker_end())) {
                meetingRoom_update += ",circle_time_piker_end='" + meetingRoomPullDTO.getCircle_time_piker_end() + "'";
            }


            if (null != meetingRoomPullDTO.getPre_time_warn() && !"".equals(meetingRoomPullDTO.getPre_time_warn())) {
                meetingRoom_update += ",pre_time_warn='" + meetingRoomPullDTO.getPre_time_warn() + "'";
            }

            if (null != meetingRoomPullDTO.getCreate_time() && !"".equals(meetingRoomPullDTO.getCreate_time())) {
                meetingRoom_update += ",create_time='" + meetingRoomPullDTO.getCreate_time() + "'";
            }
            if (null != meetingRoomPullDTO.getIssendemail() && !"".equals(meetingRoomPullDTO.getIssendemail())) {
                meetingRoom_update += ",issendemail='" + meetingRoomPullDTO.getIssendemail() + "'";
            }
            if (null != meetingRoomPullDTO.getIswriteschedule() && !"".equals(meetingRoomPullDTO.getIswriteschedule())) {
                meetingRoom_update += ",iswriteschedule='" + meetingRoomPullDTO.getIswriteschedule() + "'";
            }

            if (null != meetingRoomPullDTO.getAttachment_id() && !"".equals(meetingRoomPullDTO.getAttachment_id()) && null != meetingRoomPullDTO.getFilestream() && !"".equals(meetingRoomPullDTO.getFilestream())) {
                //调用修改文件方法
                updateImage(meetingRoomPullDTO);
            } else if (null != meetingRoomPullDTO.getFilestream() && !"".equals(meetingRoomPullDTO.getFilestream())) {
                String uid = getImage(meetingRoomPullDTO);
                meetingRoom_update += ",attachment_id='" + uid + "'";

            }

            if (null != meetingRoomPullDTO.getWeeks() && !"".equals(meetingRoomPullDTO.getWeeks())) {
                meetingRoom_update += ",weeks='" + meetingRoomPullDTO.getWeeks() + "'";
            }

            meetingRoom_update += " where meeting_room_id='" + meetingRoomPullDTO.getMeeting_room_id() + "'";
            //更新会议室表
            resultls = addReportingTo(meetingRoom_update);
        }

        if (resultls != 0) {
            resultDTO.setStr(meetingRoomPullDTO.getMeeting_room_id());
            resultDTO.setStatus("90000");
            resultDTO.setDescritpion(warnSrc.update_success);

            WorkFlowPullDTO workFlowPullDTO = new WorkFlowPullDTO();
            workFlowPullDTO.setWork_flow_formid(meetingRoomPullDTO.getMeeting_room_id());
            workFlowPullDTO.setWork_flow_approval(meetingRoomPullDTO.getReport_people());
            workFlowPullDTO.setWork_flow_approval_organization_id(meetingRoomPullDTO.getWork_flow_approval_organization_id());
            workFlowPullDTO.setIsverify("0");
            workFlowResource.updateWorkFlowInfo(workFlowPullDTO);//更新信息表

        } else {
            resultDTO.setStatus("90001");
            resultDTO.setDescritpion(warnSrc.update_fail);
        }

        return resultDTO;
    }

    /**
     * 删除会议室信息
     *
     * @param meetingRoomPullDTO
     * @return
     */
    public ResultDTO deleteMeetingRoomInfo(MeetingRoomPullDTO meetingRoomPullDTO) {

        //删除之前查看该表是否有记录
        String sql = "select count(1) from meeting_room where meeting_room_id='" + meetingRoomPullDTO.getMeeting_room_id() + "'";
        String existName = getReportingToOne(sql);

        int result = 0;

        ResultDTO resultDTO = new ResultDTO();

        if (!existName.equals("0")) {
            String QUERY = "";
            QUERY += "delete from meeting_room where meeting_room_id='" + meetingRoomPullDTO.getMeeting_room_id() + "'";

            result = this.addReportingTo(QUERY);
        }

        if (result != 0) {

            MeetingPullDTO meetingPullDTOdelete = new MeetingPullDTO();
            meetingPullDTOdelete.setMeeting_room_id(meetingRoomPullDTO.getMeeting_room_id());
            meetingResource.deleteMeetingInfo(meetingPullDTOdelete);
            DiaryTaskPullDTO diaryt=new DiaryTaskPullDTO();
            diaryt.setMeeting_room_id(meetingRoomPullDTO.getMeeting_room_id());
            taskResource.deleteDiaryTaskInfo(diaryt);

            resultDTO.setStatus("90000");
            resultDTO.setDescritpion(warnSrc.delete_success);

            WorkFlowPullDTO workFlowPullDTO = new WorkFlowPullDTO();
            workFlowPullDTO.setWork_flow_formid(meetingRoomPullDTO.getMeeting_room_id());
            workFlowResource.deleteWorkFlowInfo(workFlowPullDTO);
        } else {
            resultDTO.setStatus("90001");
            resultDTO.setDescritpion(warnSrc.delete_fail);

        }
        return resultDTO;
    }

    /**
     * 保存图片方法
     *
     * @param
     * @return
     */
    public String getImage(MeetingRoomPullDTO meetingRoomPullDTO) {
        ResultDTO resultDTO = new ResultDTO();
        // TODO Auto-generated method stub
        String enpenform_image = "";
        //获取配置图片地址
        String[] image_path = this.getImage_path();
        String image_pathAddr = image_path[1];//服务器项目目录地址
        String image_pathSerAddr = image_path[2];//图片访问地址
        String imgDirct = image_pathAddr + "/meetingroom";
        File f = new File(imgDirct);
        if (!f.exists()) {
            f.mkdirs();
            f.setWritable(true, false);
        }
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");

        String imgPath = imgDirct + "/" + meetingRoomPullDTO.getFile_type();


        //base64字符串保存为图片
        boolean headImg = FileProcess.GenerateImage(meetingRoomPullDTO.getFilestream(), imgPath);
        FileProcess.newlog("执行头像图片储存方法，储存照片地址：" + imgPath + " 方法返回：" + headImg);
        int resultls = 0;
        int mresult = 0;

        String imgurl = "/meetingroom/" + meetingRoomPullDTO.getFile_type();

        //ArrayList<HeadPortaitDTO> result = new ArrayList<HeadPortaitDTO>();

        if (headImg) {
            //插入头像表
            enpenform_image += "insert into attachment(attachment_id,attachment_addr,head_portrait_time,file_type,file_name) values ('" + uuid + "','" + imgurl + "','" + df.format(new Date()) + "','" + meetingRoomPullDTO.getFile_type() + "','" + meetingRoomPullDTO.getFile_name() + "')";
            // enpenform_image += "insert into file(file_id,file_addr,file_time,filegui_id,file_name) values ('" + uuid + "','" +imgurl+ "','" +df.format(new Date()) + "','" + dataDTO.getFilegui_id() + "','" + dataDTO.getFiletype() + "')";
            //执行sql
            resultls = addReportingTo(enpenform_image);
            if (resultls != 0) {
                return uuid;
            }else {
                return null;
            }
        }

        return null;
    }

    /**
     * 修改图片方法
     *
     * @param
     * @return
     */
    public String updateImage(MeetingRoomPullDTO meetingRoomPullDTO) {
        // TODO Auto-generated method stub
        String enpenform_image = "";
        //获取配置图片地址
        String[] image_path = this.getImage_path();
        String image_pathAddr = image_path[1];//服务器项目目录地址
        String image_pathSerAddr = image_path[2];//图片访问地址
        String imgDirct = image_pathAddr + "/meetingroom";
        File f = new File(imgDirct);
        if (!f.exists()) {
            f.mkdirs();
            f.setWritable(true, false);
        }
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");

        String imgPath = imgDirct + "/" + meetingRoomPullDTO.getFile_type();

        //base64字符串保存为图片
        boolean headImg = FileProcess.GenerateImage(meetingRoomPullDTO.getFilestream(), imgPath);
        FileProcess.newlog("执行头像图片储存方法，储存照片地址：" + imgPath + " 方法返回：" + headImg);
        int resultls = 0;
        int mresult = 0;

        String imgurl = "/meetingroom/" + meetingRoomPullDTO.getFile_type();

        //ArrayList<HeadPortaitDTO> result = new ArrayList<HeadPortaitDTO>();

        if (headImg) {
            //修改头像表
            enpenform_image += "update attachment set attachment_addr='" + imgurl + "',head_portrait_time = '" + df.format(new Date()) + "',file_type = '" + meetingRoomPullDTO.getFile_type() + "',file_name = '" + meetingRoomPullDTO.getFile_name() + "' where attachment_id='" + meetingRoomPullDTO.getAttachment_id() + "'";
            // enpenform_image += "insert into attachment(attachment_id,attachment_addr,head_portrait_time) values ('" + uuid + "','" + imgurl + "','" + df.format(new Date()) + "')";
            //执行sql
            resultls = addReportingTo(enpenform_image);
        }


        if (resultls != 0) {
            return uuid;
        }
        return null;
    }
}
